#define _CRT_SECURE_NO_WARNINGS 1

struct ListNode* rotateRight(struct ListNode* head, int k) {
    if (head == NULL || head->next == NULL)
    {
        return head;
    }
    int count = 1;
    struct ListNode* pcur = head;
    while (pcur->next)
    {
        count++;
        pcur = pcur->next;
    }
    pcur->next = head;
    k = k % count;
    int num = count - k;
    while (num--)
    {
        head = head->next;
    }
    pcur = head;
    while (--count)
    {
        pcur = pcur->next;
    }
    pcur->next = NULL;

    return head;
}